/****************************************************************************
 *   Author:yangdongy 
 *   ReadMe:引入通用的js
 *****************************************************************************/

var rootpath = Global.contextPath;

var jslib_path_prefix = rootpath + "/script/common/";
var csslib_path_prefix = rootpath + "/script/common/css/"  
//alert(jslib_path_prefix);  
//alert(csslib_path_prefix);
var importjs = function (js_file,path) {
   var js_path = path ||  jslib_path_prefix;
   document.write('<script src="'+ js_path + js_file + '" type="text/JavaScript"><\/script>');
};
var importcss = function(css_file,path){
    var css_path = path ||  csslib_path_prefix;
    document.write('<link href="'+ css_path + css_file + '" type="text/css" rel="stylesheet"/>');
};


importcss("logger.css");
importjs("json.js");
importjs("prototype.js");
importjs("jkl-floating.js");
importjs("logger.js");
importjs("select_link.js");
importjs("encoder-core.js");

// DOM2
if (typeof window.addEventListener != "undefined")
    window.addEventListener("load", function () {
    	_focusEdit();
    	//添加focus函数
    	document.body.attachEvent('onkeydown', _addOnkeyDown);
	}, false);

// IE
else if (typeof window.attachEvent != "undefined") {
    //往页面上body元素上添加默认的回车跳转功能事件
	window.attachEvent('onload', function () {
    	_focusEdit();
    	//添加focus函数
   		 document.body.attachEvent('onkeydown', _addOnkeyDown);
	});
}

/**
 * body上回车跳转功能
 * 在textarea元素上通过ctrl＋回车，进行textarea中回车编辑
 */
function _addOnkeyDown() {
    with (window.event) {
        var type1 = srcElement.type;
        if (keyCode == 13) {
            if (ctrlKey && type1 == "textarea") {
                //ctrl + 回车，且textarea ，编辑状态
                window.clipboardData.setData('text', '\n');
                document.execCommand("Paste");
                return;
            } else if (type1 == 'text' || type1 == 'radio' || type1 == 'checkbox' || type1 == 'textarea' || srcElement.tagName == 'SELECT' || type1 == 'password' || type1 == 'file') {
                keyCode = 9;
                return;
            }
            else if (type1 == 'button' || type1 == 'reset' || type1 == 'submit') return;
            //其他元素不执行此事件
            returnValue = false;
        }
    }
}

/*
*  页面load后，焦点聚焦到第一个form中的可编辑元素中
*/
function _focusEdit() {
    with (document) {
        if (forms[0] != null) {
            for (var i = 0; i < forms[0].elements.length; i++) {
                var e = forms[0].elements[i];
                if (e.type != 'hidden' && !e.disabled && !e.readOnly) {
                	try{
                    	e.focus();
                    }catch(e){/*ignore ex*/}
                    break;
                }
            }
        }
    }
}



